package com.steven.sample.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.TextView;

import com.steven.sample.R;
import com.steven.sample.view.TestView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import lib.self.acitivity.TestAcitivty;
import lib.self.utils.AutoFitUtil;
import lib.self.utils.LogUtil;


public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getSimpleName();

    @BindView(R.id.main_tv_list)
    TextView mTvList;
    @BindView(R.id.main_test)
    TestView mainTest;
    @BindView(R.id.scorllView)
    HorizontalScrollView scorllView;

    private int mTimes = 1;

    private ArrayList<String> mList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        SpannableStringBuilder builder = new SpannableStringBuilder("每单10%-20%成单金额奖励");
        ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
        ForegroundColorSpan whiteSpan = new ForegroundColorSpan(Color.WHITE);
        ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.BLUE);
        ForegroundColorSpan greenSpan = new ForegroundColorSpan(Color.GREEN);
        ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);

        builder.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(whiteSpan, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        builder.setSpan(blueSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(greenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(yellowSpan, 4, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mTvList.setText(builder);

        test();

        LogUtil.e(TAG, "scale = " + 1080 * AutoFitUtil.getScale(this));
    }

    private void test() {
        mList = new ArrayList<>();
        mList.add("0单");
        mList.add("10单");
        mList.add("20单");
        mList.add("30单");
        mList.add("40单");
        mList.add("50单");
        mList.add("60单");
        mList.add("70单");
        mList.add("80单");
        mList.add("90单");
        mainTest.setSegmentNum(mList.size());
        mainTest.setUnitList(mList);

        scorllView.post(new Runnable() {
            @Override
            public void run() {
                scorllView.scrollTo(800, 0);
            }
        });
    }

    @OnClick(R.id.main_tv_list)
    void onClick(View view) {
        switch (view.getId()) {
            case R.id.main_tv_list: {
                Intent intent = new Intent();
                intent.setClass(this, TestAcitivty.class);
                startActivity(intent);
//                ToastUtil.showToast(this, "第" + mTimes + "次点击");

                mTimes++;
            }
            break;
        }
    }
}
